#Appendix C: Risk enhancement test (full results)

#Changing conflict conditions (Table C1)
#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28] #Remove missing data (function does not have built-in listwise deletion)
countries<-countries[-129]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")
#Error means there are no observed mk_onset in democracy; recorded as 0


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-55]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
countries<-countries[-106]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
countries<-countries[-106]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Popular civilian mobilization (Table C2)
#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
countries<-countries[-130] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-85]
countries<-countries[-130]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Regime type
#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-31] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-59] 
countries<-countries[-31] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-31]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-59]
countries<-countries[-31]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-65]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-26]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-20]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-13] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-13]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-10] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-10]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Threats to leadership integrity (Table C3)
#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "unsuccessful_coup", "mk_onset")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "pt_success", "mk_onset")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

